﻿<Window x:Class="Istacee.Personal.Desktop.TimeWatcher.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:TimeWatcher="clr-namespace:Istacee.Personal.Desktop.TimeWatcher"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Title="TimeWatcher Beta - Keep track of your working time - A beer powered software" 
        Height="350" Width="600" 
        Icon="..\img\cronometro_chronometer_watch_icon-555px.ico">
    <Window.Resources>
        <TimeWatcher:TaskStateToStringConverter x:Key="TaskStateToStringConverter" />
        <TimeWatcher:BoolToDetailVisiblityConverter x:Key="VisibilityToVisibilityButtonNameConverter" />
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="35" />
            <RowDefinition />
            <RowDefinition Height="35" />
        </Grid.RowDefinitions>
        <ToolBarTray Background="White" Grid.Row="0">
            <ToolBar Band="1" BandIndex="1">
                <Button Command="{Binding AddTaskCommand}" ToolTip="Add new task">
                    <Image Source="..\img\Add-New.png" Height="25"/>
                </Button>
                <Button Command="{Binding LoadCommand}" ToolTip="Reload from disk">
                    <Image Source="..\img\Reload.png" Height="25"/>
                </Button>
                <Button Command="{Binding SaveCommand}" ToolTip="Save to disk">
                    <Image Source="..\img\Save.png" Height="25" />
                </Button>
                <ToggleButton Content="Show Details" x:Name="visibilityDetailButton" />
            </ToolBar>
        </ToolBarTray>
        <DataGrid Grid.Row="1" ItemsSource="{Binding Tasks}" AutoGenerateColumns="False" CanUserAddRows="False" SelectionMode="Single" x:Name="dg">
            <DataGrid.RowDetailsTemplate>
                <DataTemplate DataType="TimeWatcher:TrackedTask">
                    <Grid Visibility="{Binding ElementName=visibilityDetailButton, Path=IsChecked, Converter={StaticResource ResourceKey=VisibilityToVisibilityButtonNameConverter}}">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <GroupBox Grid.Row="0" Margin="5, 0, 5, 3" Header="Alarm">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="80" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <RadioButton GroupName="basis" Grid.Row="1" Content="Ponctual" Name="ponctual_basis" IsChecked="{Binding PonctualBasis, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
                                <xctk:DateTimeUpDown Grid.Row="1" Grid.Column="1" Format="FullDateTime" Value="{Binding AlarmTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                <RadioButton GroupName="basis" Content="Period" Name="period_basis"/>
                                <xctk:DateTimeUpDown Grid.Column="1" Format="LongTime" />
                                <Button Margin="0,5,0,2" Grid.Row="2" Content="Set" Grid.ColumnSpan="2" />
                            </Grid>
                        </GroupBox>
                    </Grid>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
            <DataGrid.Columns>
                <DataGridTextColumn x:Name="col_name" Width="350" Header="Name" IsReadOnly="False" Binding="{Binding Name, Mode=TwoWay}">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="{x:Type TextBlock}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Status}" Value="True">
                                    <Setter Property="Background" Value="LightGreen"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Status}" Value="False">
                                    <Setter Property="Background" Value="LightPink"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Header="ElapsedTime" Binding="{Binding ElapsedTime}" IsReadOnly="True" />
                <DataGridTemplateColumn Header="">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Command="{Binding TaskActionCommand}" Content="{Binding Status, Converter={StaticResource ResourceKey=TaskStateToStringConverter}}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        <StatusBar Grid.Row="2">
            <Label Content="{Binding ApplicationStatus}" />
            <Label Content="{Binding Message}" />
        </StatusBar>
    </Grid>
</Window>
